package com.example.cwproject.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Result {

    public static final String CODE_SUCCESS = "200";
    public static final String CODE_AUTH_ERROR = "401";
    public static final String CODE_SYS_ERROR = "500";

    private String code;  //请求的返回编码
    private String msg;   //表示错误的详细信息
    private Object data;  //表示数据从何返回出去

    public static Result success(){
        return new Result(CODE_SUCCESS,"Success",null);
        //return Result.builder().code(CODE_SUCCESS).msg("请求成功").build();
    }

    public static Result success(Object data){
        return new Result(CODE_SUCCESS,"Success",data);
    }

    public static Result error(String msg){
        return new Result(CODE_SYS_ERROR,msg,null);
    }

    public static Result error(String code,String msg){
        return new Result(code,msg,null);
    }

    public static Result error(){
        return new Result(CODE_SYS_ERROR,"System fail",null);
    }

}
